//
//  BNRItemViewController.m
//  Homepwer
//
//  Created by wangcarl on 16/5/15.
//  Copyright © 2016年 wangcarl. All rights reserved.
//

#import "BNRItemViewController.h"
#import "BNRItem.h"
#import "BNRItemStore.h"

@implementation BNRItemViewController

-(instancetype) init
{
    self=[super initWithStyle:UITableViewStylePlain];
    
    if (self) {
        for (int i=0; i<5; i++) {
            [[BNRItemStore sharedStore] createItem];
        }
    }
    
    return self;
}

-(instancetype)initWithStyle:(UITableViewStyle)style
{
    return [self init];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[[BNRItemStore sharedStore] allItems] count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    NSArray *items=[[BNRItemStore sharedStore] allItems];
    BNRItem *item=items[indexPath.row];
    cell.textLabel.text=[item description];
    return cell;
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
}

@end
